package cn.hill4j.tool.spring.ext.iop.dynamic;

import cn.hill4j.tool.spring.ext.iop.feign.IopFeignClientBuilder;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
  * ClassName: DymFeignIopClientsBuilder
  * Description: 动态feignClient bean构造器
  * @author hillchen
  * Date: 2023/8/11
  * @version: 1.0
  */
public class DymFeignIopClientsBuilder extends BaseDymIopClientBuilder implements  ApplicationContextAware {
    /**
     * spring上下文容器
     */
    private ApplicationContext applicationContext;
    /**
     * 404编码标志
     */
    private boolean decode404;
    /**
     * 异常回调处理类
     */
    private Class<?> fallback = void.class;
    /**
     * 异常回调处理构造工厂类
     */
    private Class<?> fallbackFactory = void.class;

    @Override
    public DymIopClientFactory getObject() throws Exception {
        IopFeignClientBuilder iopFeignClientBuilder = new IopFeignClientBuilder(applicationContext,
                contextId(),decode404,fallback,fallbackFactory,getObjectType());
        return new DymFeignIopClientFactory(getInterfaceClazz(),getDymKeySelector(),iopFeignClientBuilder);
    }

    @Override
    public Class<?> getObjectType() {
        return DymFeignIopClientFactory.class;
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
    /**
     * @author hillchen
     * Description: 设置404编码标志
     * Date: 2023/8/11 00:31
     * @param decode404 404编码标志
     **/
    public void setDecode404(boolean decode404) {
        this.decode404 = decode404;
    }
    /**
     * @author hillchen
     * Description: 设置异常回调处理类
     * Date: 2023/8/11 00:32
     * @param fallback 异常回调处理类
     **/
    public void setFallback(Class<?> fallback) {
        this.fallback = fallback;
    }

    /**
     * @author hillchen
     * Description: 设置异常回调处理构造工厂类
     * Date: 2023/8/11 00:32
     * @param fallbackFactory 异常回调处理构造工厂类
     **/
    public void setFallbackFactory(Class<?> fallbackFactory) {
        this.fallbackFactory = fallbackFactory;
    }
}
